Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Use LNC to connect to the LND node #98

Merged
merged 9 commits into from
Jul 5, 2023

Conversation

positiveblue
Copy link
Contributor

@positiveblue positiveblue commented Jun 6, 2023

Allow aperture to connect to LND using LNC

config.go Outdated Show resolved Hide resolved
sample-conf.yaml Outdated Show resolved Hide resolved
aperturedb/sqlc/migrations/000003_lnc-sessions.down.sql Outdated Show resolved Hide resolved
aperturedb/sqlc/migrations/000003_lnc-sessions.up.sql Outdated Show resolved Hide resolved
aperturedb/sqlc/migrations/000003_lnc-sessions.up.sql Outdated Show resolved Hide resolved
lnc/lnc.go Outdated Show resolved Hide resolved
lnc/lnc.go Show resolved Hide resolved
lnc/session.go Show resolved Hide resolved
challenger.go Show resolved Hide resolved
lnc/lnc.go Outdated Show resolved Hide resolved
@positiveblue positiveblue marked this pull request as ready for review June 27, 2023 22:59
@lightninglabs-deploy
Copy link
Collaborator

@positiveblue, remember to re-request review from reviewers when ready

Copy link
Member

@ellemouton ellemouton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something needs to block calls until the connection is ready. Also maybe some info logs to say where the connection is at.

Ran into this panic while testing.

2023/06/30 11:36:31 http: panic serving 127.0.0.1:65481: runtime error: invalid memory address or nil pointer dereference                                                                                                                     [6/477]
goroutine 84 [running]:
net/http.(*conn).serve.func1()
        /usr/local/go/src/net/http/server.go:1850 +0xb0
panic({0x1056daf60, 0x106493e90})
        /usr/local/go/src/runtime/panic.go:890 +0x258
github.com/lightninglabs/aperture.(*LndChallenger).NewChallenge(0x0, 0x14000bec000?)
        /Users/elle/ll/aperture/challenger.go:269 +0x28
github.com/lightninglabs/aperture/mint.(*Mint).MintLSAT(0x140007929c0, {0x105927f08, 0x140001a2000}, {0x140003504e0, 0x1, 0x1})
        /Users/elle/ll/aperture/mint/mint.go:110 +0x68
github.com/lightninglabs/aperture/auth.(*LsatAuthenticator).FreshChallengeHeader(0x140008bc000, 0x1400029a700, {0x14000040700, 0x8}, 0xa)
        /Users/elle/ll/aperture/auth/authenticator.go:86 +0xb8
github.com/lightninglabs/aperture/proxy.(*Proxy).handlePaymentRequired(0x1400018e050, {0x105926fd0, 0x1400037e460}, 0x1400029a700, {0x14000040700, 0x8}, 0x1018?)
        /Users/elle/ll/aperture/proxy/proxy.go:403 +0x70
github.com/lightninglabs/aperture/proxy.(*Proxy).ServeHTTP(0x1400018e050, {0x105926fd0, 0x1400037e460}, 0x1400029a700)
        /Users/elle/ll/aperture/proxy/proxy.go:177 +0x2f8
net/http.HandlerFunc.ServeHTTP(0x14000080948?, {0x105926fd0?, 0x1400037e460?}, 0x40?)
        /usr/local/go/src/net/http/server.go:2109 +0x38
golang.org/x/net/http2/h2c.h2cHandler.ServeHTTP({{0x10591dca0?, 0x140003fe480?}, 0x1400018e140?}, {0x105926fd0, 0x1400037e460}, 0x1400029a700)
        /Users/elle/go/pkg/mod/golang.org/x/net@v0.10.0/http2/h2c/h2c.go:125 +0x41c
net/http.serverHandler.ServeHTTP({0x14000bacd20?}, {0x105926fd0, 0x1400037e460}, 0x1400029a700)

config.go Outdated Show resolved Hide resolved
config.go Outdated Show resolved Hide resolved
config.go Outdated Show resolved Hide resolved
sample-conf.yaml Outdated Show resolved Hide resolved
lnc/store.go Outdated Show resolved Hide resolved
lnc/log.go Show resolved Hide resolved
lnc/lnc.go Outdated Show resolved Hide resolved
pricesrpc/prices.swagger.json Outdated Show resolved Hide resolved
aperture.go Outdated Show resolved Hide resolved
config.go Outdated Show resolved Hide resolved
sample-conf.yaml Outdated Show resolved Hide resolved
lnc/lnc.go Outdated Show resolved Hide resolved
lnc/lnc.go Outdated Show resolved Hide resolved
lnc/lnc.go Outdated Show resolved Hide resolved
aperturedb/lnc_sessions.go Outdated Show resolved Hide resolved
aperturedb/lnc_sessions.go Outdated Show resolved Hide resolved
aperturedb/lnc_sessions.go Outdated Show resolved Hide resolved
aperture.go Outdated Show resolved Hide resolved
aperture.go Outdated Show resolved Hide resolved
Stop creating the connection inside the `NewLndChallenger`. That will
allow us reuse the function with an LNC connection.
Whenever we use the LightningClient from an LNC connection we need to
add the macaroon to the headers.
The new package contains a new interface (`Challenger`) that any
new challenger must implement.

Because aperture uses the new interface instead of using directly the
`LndChallenger` struct I added the `Stop()` method to the
`mint.Challenger`. Instead of also adding the `Start()` method the constructor
returns a Challenger already "started".
if !a.cfg.Authenticator.Disable {
genInvoiceReq := func(price int64) (*lnrpc.Invoice, error) {
return &lnrpc.Invoice{
Memo: "LSAT",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking, but in the future we can insert relevant endpoint/context information here so someone can build a UI/dashboard on top of lnd/aperture to do things like track the amount earned from a given endpoint, etc.

To do this, we'd need to expose the memo as part of the challenger interface, as only much later in the pipeline do we have the full request context information.

@@ -263,7 +239,9 @@ func (l *LndChallenger) Stop() {
// request (invoice) and the corresponding payment hash.
//
// NOTE: This is part of the mint.Challenger interface.
func (l *LndChallenger) NewChallenge(price int64) (string, lntypes.Hash, error) {
func (l *LndChallenger) NewChallenge(price int64) (string, lntypes.Hash,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re the above comment, we could pass in the additional context here as an optional argument. Then the invoice creation has a chance to tag any extra details.


// MailboxAddress is the address of the mailbox that the client will
// use for the LNC connection.
MailboxAddress string `long:"mailboxaddress" description:"the host:port of the mailbox server to be used"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have a default mailbox addr we use here.

Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🔌

Fixed some issues I ran into in #103!

@Roasbeef Roasbeef merged commit 510d409 into lightninglabs:master Jul 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants